import { getArticleDetail } from '@/apis/article'

const state = {
    currentMenuId: 1, // 当前管理中心分类id
    // 导航菜单项
    adminNavItems: [
        { url: 'drawer_003', isSelected: true, text: '文章管理', id: 1 },
        { url: 'drawer_004', isSelected: false, text: '个人资料', id: 2 },
        { url: 'drawer_005', isSelected: false, text: '账号设置', id: 3 },
        { url: 'drawer_006', isSelected: false, text: '消息中心', id: 4 },
    ],
}

const mutations = {
    // 设置当前管理中心分类id
    setCurrentMenuId(state, id) {
        state.currentMenuId = id
        // 当前菜单id为选中项
        state.adminNavItems.forEach(item => {
            item.isSelected = item.id === id
        })
    },
}

const actions = {
    // 获取文章详情
    getArticleDetail(ctx, data) {
        return new Promise((resolve, reject) => {
            getArticleDetail(data).then(res => {
                if (res.code === 200) {
                    resolve(res)
                } else {
                    console.log('获取文章详情失败')
                    reject(res)
                }
            }).catch(err => {
                console.log('获取文章详情失败')
            })
        })
    }
}

const getters = {

}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}
